package com.klikmee.sms.core.commons.events;

import java.util.HashMap;

/**
 * Represents sms core event. Used carry event notifications through out the
 * application and inform subscribed components that some king of event has
 * happened. It can carry additional event data.
 * 
 * @author makcro
 * 
 */
public class AppEvent {

	/**
	 * Map of additional event data
	 */
	private HashMap<String, Object> dataMap = new HashMap<String, Object>();

	/**
	 * Single instance of event data
	 */
	private Object eventData;

	/**
	 * Unique identifier of event
	 */
	private String eventType;

	/**
	 * @param eventData
	 * @param eventType
	 */
	public AppEvent(String eventType, Object eventData) {
		super();
		this.eventData = eventData;
		this.eventType = eventType;
	}

	public AppEvent() {

	}

	public AppEvent(String eventType) {
		this.eventType = eventType;
	}

	/**
	 * Gets event single addiotnal data
	 * 
	 * @param <T>
	 * @return
	 */
	public <T> T getData() {
		return (T) this.eventData;
	}

	/**
	 * Gets event's additional data by key
	 * 
	 * @param <T>
	 * @param key
	 * @return
	 */
	public <T> T getData(String key) {
		return (T) dataMap.get(key);
	}

	public void setData(Object object) {
		this.eventData = object;
	}

	public void setData(String key, Object value) {
		this.dataMap.put(key, value);
	}

	public String getEventType() {
		return eventType;
	}

	public void setEventType(String eventType) {
		this.eventType = eventType;
	}
}
